#
# explosion.py -- rendering explosions
# 
# author: Tom "Knio" Flanagan
#         knio@h4xn3t.net
#         theknio@gmail.com
#         irc.freenode.net - Knio - #python #pygame #py
#
# this file released under Public Domain
#

from constants import * 
import object

class Explosion(object.Object):
    explosion = {}

    def init(self):
        self.image = pygame.image.load('images/explosion.bmp').convert()

    def sprite(self, n):
        n = int(n)
        if n not in self.explosion:
            self.explosion[n] = pygame.transform.scale(self.image, (int(n*3),)*2)
        return self.explosion[n]
        
    def tick(self):
        self.view.dirty.append(pygame.Rect(self.rect))
        self.rect.size = (int(self.model.currentsize)*2.5,) *2
        self.rect.centerx = self.view.offset+self.model.x
        self.rect.centery = self.view.offset-self.model.y
        self.view.dirty.append(pygame.Rect(self.rect))
        self.render()
        
    def render(self):
        sprite = self.sprite(self.model.currentsize)
        sprite.set_alpha(int(255*self.model.power))
        self.view.screen.blit(sprite, self.rect)
        
